package com.wang.designPattern.singleton;

/**
 * @description 静态内部类单例模式
 * @Author wangzilong
 * @Date 2025/1/6 8:45
 */
public class StaticInnerClassSingleton {
    private StaticInnerClassSingleton(){
        if(SingletonHolder.instance != null){
            throw new RuntimeException("不允许创建多个实例");
        }
    }

    public static StaticInnerClassSingleton getInstance(){
        return SingletonHolder.instance;
    }

    // 静态内部类
    private static class SingletonHolder{
        private static final StaticInnerClassSingleton instance = new StaticInnerClassSingleton();
    }
}
